/**
 * @Description : _checkbox.js
 * @Author : Tomi
 * @Email : lintaoming@qq.com
 * @Create : 2017/8/31
 */
(function(window, $, undefiend){
    'use strict';
    $(window.document).ready(function(){
        $('input[type="checkbox"]').each(function(i,e){
            var $e = $(e);

            if($e.data('all')){
                var $subCheck = $('[data-name="'+$e.data('name')+'"]').not($e),
                    num = 0;

                $e.on('ifClicked', function(ev){
                    if(!this.checked){
                        num = $subCheck.length;
                        $subCheck.iCheck('check');
                    }else{
                        num = 0;
                        $subCheck.iCheck('uncheck');
                    }
                });

                $subCheck.on('ifClicked', function(){

                    if(!this.checked){
                        num++;
                    }else{
                        num--;
                    }

                    if(num == $subCheck.length){
                        $e.iCheck('check');
                    }else{
                        $e.iCheck('uncheck');
                    }
                });
            }

            $(e).iCheck({
                checkboxClass: 'checkbox-custom',
                radioClass: 'radio-custom',
                increaseArea: '20%' // optional
            });
        });
    });
})(window, jQuery);